// import {ClassicModel} from '../../models/classic.js'
// import { LikeModel } from '../../models/like.js'
import { Ajax } from '../../util/api.js'

// let classicModel = new ClassicModel()
// let likeModel = new LikeModel()
let ajax = new Ajax()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    classic:null,
    latest:true,
    first:false,
    likeCount:0,
    likeStatus:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    ajax.classic(res=>{
      this.setData({
        classic: res.list1,
        likeCount: res.list1.fav_nums,
        likeStatus: res.list1.like_status
      })
    })
    // classicModel.getLatest((res)=>{
    //   this.setData({
    //     classic:res,
    //     likeCount:res.fav_nums,
    //     likeStatus:res.like_status
    //   })
    // })
  },

  onLike (event){
    let behavior = event.detail.behavior
    likeModel.like(behavior,this.data.classic.id,this.data.classic.type)
  },
  
  onNext() {
    // this._updateClassic('next')
    ajax.classic(res => {
      this.setData({
        classic: res.list1,
        likeCount: res.list1.fav_nums,
        likeStatus: res.list1.like_status,
        first: false,
        latest: true
      })
    })
  },
  onPrevious() {
    // this._updateClassic('previous')
    ajax.classic(res => {
      this.setData({
        classic: res.list2,
        likeCount: res.list2.fav_nums,
        likeStatus: res.list2.like_status,
        first: true,
        latest:false
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
  _updateClassic (nextOrPrevious){
    let index = this.data.classic.index
    
  },

  _getLikeStatus(artID,category){
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})